const FormatSpaceString = require('../common/FormatSpaceString');
const Img64 = require('../file/Img64');

class Organization {
    constructor(obj) {
        this.name = obj.name;
        this.description = obj.description;
        this.logo = obj.logo;
    }

    check() {
        if (!this.name || !this.description || !this.logo) {
            return { msg: '缺少参数' };
        }
        let flag;
        // 组织名称
        let name = new FormatSpaceString(this, 'name', false, false, null, 100, null, null);
        flag = name.check();
        if (!flag.success) {
            return flag;
        }
        this.name = name.OldValue;
        // 组织描述
        let description = new FormatSpaceString(this, 'description', false, false, null, 50000, null, null);
        flag = description.check();
        if (!flag.success) {
            return flag;
        }
        this.description = description.OldValue;
        // logo
        let logo = new Img64({ img: this.logo });
        flag = logo.check();
        if (!flag.success) {
            return flag;
        }
        this.logoBuffer = logo.buffer;
        return { success: true };
    }
}

module.exports = Organization;